import React from 'react';
import Login from '../login'
import Home from '../component/home'
import Mulu from '../pages/jobs/mulu/Mulu'
import Myhome from '../component/myhome'
import {
    BrowserRouter as Router,
    Route,
    Redirect
} from 'react-router-dom'
import myhome from '../component/myhome';


const PrivateRoute = ({component: Component, ...props}) => {
    // 解构赋值 将 props 里面的 component 赋值给 Component
    return <Route {...props} render={(p) => {
        const login = document.cookie.includes('isLogin=true')
        if (login){ // 如果登录了, 返回正确的路由
            return <Component />
        } else { // 没有登录就重定向至登录页面
            return <Redirect to={{
                pathname: '/',
                state: {
                    from: p.location.pathname
                }
            }}/>
        }
    }}/>
}
class Main extends React.Component{
    render(){
        return(
            <Router>
                <div style={{height:'100%'}}>
                    {/* exact 准确的，精准的，防止所有/...接口被调用 */}
                    <Route path="/" exact component={Home}></Route>
                    {/* <PrivateRoute path="/home" component={Home}/> */}
                    <Route path="/mulu" exact component={Mulu} />
                    <Route path="/myhome" exact component={Myhome} />
                </div>
            </Router>
        )
    }
}

export default Main;
